/**
 * 
 */
package metalink.admin;

import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import myutil.Connect;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import vo.ResidentialRoomVo;

/**
 * @author Sony
 *
 */
public class InsertIntoRoom extends ActionSupport{
	public String execute() {
		try {
			int count = 0;
			String query = "";
			Connect c = new Connect();
			HttpSession session = ServletActionContext.getRequest().getSession();
			ArrayList<ResidentialRoomVo> room_list = (ArrayList<ResidentialRoomVo>) session.getAttribute("uploaded_room_list");
			if (room_list != null) {
				for (ResidentialRoomVo vo : room_list) {
						query = "insert into residential_room(residential_id,room_number,occupancy,vacancy,description) values("
								+ vo.getResidential_id()
								+ ","
								+ vo.getRoom_number()
								+ ","
								+ vo.getOccupancy()
								+ ","
								+ vo.getVacancy()
								+ ",'"
								+ vo.getDescription()
								+  "')";
						System.out.println(query);
						c.dml(query);
					++count;

				}
				addActionError(count + " records are inserted successfully");
				return SUCCESS;
			}

			return ERROR;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
}
